package com.igeek.web;

import com.igeek.domain.Product;
import com.igeek.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author jerryHe
 * @create 2019-10-08 15:59
 */

@WebServlet("/indexServlet")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("test");
        //调用service
        ProductService service = new ProductService();
        List<Product> hot_products = service.getHotProducts();
        List<Product> new_products = service.getNewProducts();
        //放入request域
        request.setAttribute("hot_products",hot_products);
        request.setAttribute("new_products",new_products);
        //跳转到index.jsp
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}
